package com.pet.server.dao.common;

import java.util.Date;

import com.pet.framework.dao.util.TemplateDao;
import com.pet.framework.page.Page;
import com.pet.server.po.ProductData;
import com.pet.server.po.ProductInfo;
import com.pet.server.po.ProductView;
import com.pet.system.constants.ATTSystem;
import com.pet.system.statement.Statement;

public class ProductDao extends TemplateDao {
	
	public void searchProductAlima(ProductData pd,Page page){
		   Statement stms = stmsFactory.createStatement("from ProductData p where 1=1 and  state!=4");
					 if(null!=pd){
				     	  stms.append("and", "p.sellerId", "=", pd.getSellerId());
				     	  stms.append("and", "p.productCate", "=", pd.getProductCate());
				     	  stms.appendLike(null, "and", "p.productCate", pd.getProductCate());
				     	  stms.appendLike(null, "and", "p.petCate", pd.getPetCate());
				     	  stms.appendLike(null, "and", "p.productName", pd.getProductName());
				      }
		             stms.addOrderBy("p.id desc");
		   templateDao.search(stms, page);
		}

	public void searchProductInfo(ProductInfo product,Page page){
	   Statement stms = stmsFactory.createStatement("from ProductInfo p where 1=1 and  state!=4");
				 if(null!=product){
			     	  stms.append("and", "p.sellerId", "=", product.getSellerId());
			     	  stms.append("and", "p.productCate", "=", product.getProductCate());
			     	  stms.appendLike(null, "and", "p.productName", product.getProductName());
			      }
	             stms.addOrderBy("p.id desc");
	   templateDao.search(stms, page);
	}
	
	public void searchProductView(ProductInfo product,ProductView view,Page page){
        Statement stms = stmsFactory.createStatement("select p,pv from ProductInfo p,ProductView pv where p.id=pv.productId");
                  if(null!=product){
                	  stms.append("and", "p.sellerId", "=", product.getSellerId());
                	  stms.append("and", "p.productCate", "=", product.getProductCate());
                	  stms.appendLike(null, "and", "p.productName", product.getProductName());
                  }
                  if(null!=view){
                	  stms.append("and", "pv.viewChannel", "=", view.getViewChannel());
                	  stms.append("and", "pv.viewType", "=", view.getViewType());
                	  
                  }
                  stms.append("and","pv.state","=",ATTSystem.LOGIC_TRUE);
                  stms.addOrderBy(" pv.seq desc ,pv.id desc");
	   templateDao.search(stms, page);
	}

	public void searchDateReport(String productName,Integer productId,Date beginDate,Date endDate,Page page){
		Statement stms = stmsFactory.createStatement(" from DateReport dr where 1=1");
		          stms.appendLike(null,"and", "dr.productName", productName);
		          stms.appendBetween("and", "dr.createDate", beginDate, endDate);
		          stms.append("and", "dr.productId", "=", productId);
		          stms.addOrderBy("dr.createDate desc");
		templateDao.search(stms, page);
		          
	}
	public void searchAdvise(Page page){
		Statement stms = stmsFactory.createStatement("from AdviseInfo ai where 1=1");
		          stms.addOrderBy(" ai.id desc");
		templateDao.search(stms, page);
	}

}
